#pragma once
#include <Windows.h>
#include <string>
#include <mutex>
#include <map>
#include <vector>

namespace BackupFS
{
#define FS_MAGIC "BackupFS"
#define BACK_SLASH std::wstring(L"\\")
#define DATA_FILE std::wstring(L"BFS_DATA")
#define BITMAP_FILE std::wstring(L"BFS_BITMAP")
#define META_FILE std::wstring(L"BFS_META")
#define DEDEP_FILE std::wstring(L"BFS_DEDUP")
#define BAKUPFS_DB_FILE std::wstring(L"BFS_DB")
#define BAKUPFS_FLAG_FILE std::wstring(L"BFS_FLAG")
#define BACKUPFS_MAGIC "BackupFS\0"
#define BACKUPFS_PAGE_SIZE (LONGLONG)4096
//100G
/*
can be easily tested with different value
*/
inline	LONGLONG BACKUPFS_BITMAP_GROUP_SIZE = (LONGLONG)107374182400;
//
#define BACKUPFS_BITMAP_SIZE (LONGLONG)26214400
#define ROUND_UP_PAGES(length) (((LONGLONG)length + BACKUPFS_PAGE_SIZE - 1) / BACKUPFS_PAGE_SIZE)
#define ROUND_UP_BLOCK_SIZE(length) (((LONGLONG)length + BACKUPFS_PAGE_SIZE - 1) / BACKUPFS_PAGE_SIZE * BACKUPFS_PAGE_SIZE)
	typedef enum _FILE_TYPE_
	{
		DATA_TYPE,
		META_TYPE,
		DEDUP_TYPE,
		MAX_TYPE
	}FILE_TYPE;

	enum class DATA_ATTR
	{
		NONE_ATTR=1,
		COMPRESS_ATTR=2,
		ENCRYPT_ATTR=4,
		DEDUP_ATTR=8,
		MAX_ATTR=0x10000
	};
	enum class FILE_SYSTEM_MODE
	{
		NORMAL_MODE=0,
		DRILL_MODE=1,
		INCREMENTAL_MODE,
		MAX_MODE=0x10000
	};
	typedef struct _DATA_BLOCK_
	{
		LONGLONG Id;
		LONGLONG OffsetInFile;// offset in file self,4K align
		LONGLONG OffsetInData;// offset in data file,4k align
		LONGLONG Length;//block length,default is 4K
		DATA_ATTR Attr;
	}DATA_BLOCK, * PDATA_BLOCK;

	typedef struct _LOCK_REGION_
	{
		LONGLONG Offset;
		LONGLONG Length;
		ULONG ProcessID;
	}LOCK_REGION,*PLOCK_REGION;

	typedef struct _FS_INFO_
	{
		LONGLONG CurrentNodeId;
		LONGLONG CurrentBlockId;
		LONGLONG Size;
		LONGLONG UsedSize;
	}FS_INFO,*PFS_INFO;
	typedef struct _FILE_HEADER_
	{
		char Magic[32];
		int Version;
		int BlockSize;
		int DataOffset;//default is 4096
		FILE_TYPE FileType;

	}FILE_HEADER,*PFILE_HEADER;
}